<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function myFunction() {
            alert("Hello World!");
        }
    </script>
</head>

<body>
    <div>
        <button onclick="myFunction()">Try it</button>
    </div>
    <hr />
    <div>
        <p>点击这个按钮，来调用带参数的函数。</p>
        <button onclick="myFunction('Harry Potter','Wizard')">点击这里</button>
        <script>
            function myFunction(name, job) {
                alert("Welcome " + name + ", the " + job);
            }
        </script>
        <!-- 变量和参数必须以一致的顺序出现。第一个变量就是第一个被传递的参数的给定的值 -->
    </div>
    <hr />
    <div>
        <button onclick="myFunction('Harry Potter','Wizard')">点击这里</button>
        <button onclick="myFunction('Bob','Builder')">点击这里</button>
        <script>
            function myFunction(name, job) {
                alert("Welcome " + name + ", the " + job);
            }
        </script>
    </div>
    <hr />
    <div>
        <p>本例调用的函数会执行一个计算，然后返回结果：</p>
        <p id="demo"></p>
        <script>
            function myFunction(a, b) {
                return a * b;
            }
            document.getElementById("demo").innerHTML = myFunction(4, 3);
        </script>
        <!-- 返回值基于传递到函数中的参数 -->
    </div>
</body>

</html>